package de.hhbk.feedbackmodul.util;

import java.util.HashMap;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import de.hhbk.feedbackmodul.utilAbstract.ServiceLocator;

public class JBossServiceLocator extends ServiceLocator{
	
	private JBossServiceLocator()
	{
		
	}
	
	public static JBossServiceLocator getInstance()
	{
		if(instance == null )
		{
			cache = new HashMap<String, Object>();
			instance = new JBossServiceLocator();
		}
		return instance;
	}
	
	@Override
	public synchronized Object lookup(String jndiName, Class<?> clazz) throws NamingException {
		if(cache.get(jndiName) != null)
		{
			return cache.get(jndiName);
		}
		else
		{
			InitialContext ic = new InitialContext();
			Object o = ic.lookup(jndiName);
			cache.put(jndiName, o);
			return o;
		}
	}
	

}
